package com.person.yan.a01_retrofit.nat;

import com.google.gson.Gson;

import java.util.concurrent.TimeUnit;

import okhttp3.OkHttpClient;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * Created by ywy on 2017-09-29.
 */

public class NetInstanseUtils {

    private static TakeOutApi takeOutApi;

    public static TakeOutApi getNatInstanceApi() {

        if(takeOutApi==null){

            OkHttpClient client = new OkHttpClient().newBuilder()
                    .connectTimeout(40, TimeUnit.SECONDS)
                    .readTimeout(40, TimeUnit.SECONDS)
                    .writeTimeout(40, TimeUnit.SECONDS).build();
            Retrofit build = new Retrofit.Builder()
                    .baseUrl("http://192.168.1.101:8080/TakeoutServer/")
                    .client(client)
                    .addConverterFactory(GsonConverterFactory.create(new Gson()))
                    .build();


            takeOutApi = build.create(TakeOutApi.class);

        }


        return takeOutApi;
    }

}
